package es.uab.sound.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class Settings {

	/** General Settings **/
	public static final String DECIMALS = "decimals";
	public static final String FREQUENCY = "frequency";

	/** Graph Settings **/
	public static final String AXES = "graph_axes";
	public static final String GRID = "graph_grid";
	public static final String LENGEND = "graph_legend";
	public static final String ZOOM = "graph_zoom";
	public static final String YMAX = "graph_ymax";
	public static final String YMIN = "graph_ymin";

	/** Network Settings **/
	public static final String SEND_TO_SERVER = "network_send";
	public static final String SERVER_URL = "server_data";

	private SharedPreferences sharedPref;

	public Settings(Context context) {
		sharedPref = PreferenceManager.getDefaultSharedPreferences(context);
		Logger.info(this, "sharedPref:" + sharedPref.getAll());
	}

	/** General Settings **/
	public int getDecimals() {
		String intValue = sharedPref.getString(DECIMALS, "2");
		return Integer.parseInt(intValue);
	}

	public int getFrequency() {
		String intValue = sharedPref.getString(FREQUENCY, "16000");
		return Integer.parseInt(intValue);
	}

	/** Graph Settings **/
	public boolean isShowAxes() {
		return sharedPref.getBoolean(AXES, true);
	}

	public boolean isShowGrid() {
		return sharedPref.getBoolean(GRID, true);
	}

	public boolean isShowLegend() {
		return sharedPref.getBoolean(LENGEND, false);
	}

	public boolean isShowZoom() {
		return sharedPref.getBoolean(ZOOM, true);
	}

	public int getYMin() {
		String intValue = sharedPref.getString(YMIN, "35");
		return Integer.parseInt(intValue);
	}

	public int getYMax() {
		String intValue = sharedPref.getString(YMAX, "110");
		return Integer.parseInt(intValue);
	}

	/** Network Settings **/
	public boolean isSendToServer() {
		return sharedPref.getBoolean(SEND_TO_SERVER, false);
	}

	public String getURLServer() {
		return sharedPref.getString(SERVER_URL, "http://192.168.1.34/android");
	}

}
